﻿@model TBlog.Web.Models.Article
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_ManageLayoutPage.cshtml";
    var categorylist = ViewBag.Category as IList<TBlog.Web.Models.Category>;
}

<blockquote class="layui-elem-quote">
    <span class="layui-breadcrumb">
        <a href="@Url.Action("GetListArticle", "Article")">文章管理</a>
        <a href="javascript:;">编辑文章</a>
    </span>
</blockquote>

@if (ViewBag.IsError != null && ViewBag.IsError)
{
    <div style="background-color: #ff6a00; border-color: aqua; color: #4cff00; padding: 15px; border-radius: 5px; position: relative;">
        <p><strong>错误信息：</strong>有字段内容不合法</p>
        <a href="javascript:;" style="position: absolute; right: 17px; top: 17px"><i class="layui-icon">&#x1006;</i></a>
    </div>
}
<fieldset class="layui-elem-field layui-field-title">
    <legend>编辑文章</legend>
</fieldset>
@using (Html.BeginForm("Edit", "Article", FormMethod.Post, new { @class = "layui-form" }))
{
    @Html.AntiForgeryToken();
    <form class="layui-form">
        <input type="hidden" name="id" value="@Model.ID"/>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="Title" lay-filter="title" class="layui-input"  autocomplete="off" value="@Model.Title" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">作者</label>
            <div class="layui-input-block">
                <input type="text" name="Author" lay-filter="title" class="layui-input"  autocomplete="off" value="@Model.Author" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-block">
                <select name="categoryID">
                    @if (categorylist != null && categorylist.Count > 0)
                    {
                        foreach (var item in categorylist)
                        {

                            if (@item.ID == @Model.CategoryID)
                            {
                        <option value="@item.ID" selected="selected">@item.CategoryName</option>
                            }
                            else
                            {
                        <option value="@item.ID" >@item.CategoryName</option>
                            
                            }
                        }
                    }
                    <option></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标签</label>
            <div class="layui-input-block">
                <input type="text" name="Tags" lay-filter="title" class="layui-input"  autocomplete="off" value="@Model.Tags" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="State">
                    @if (Model.State == 0)
                    {
                        <option value="0" selected="selected">全部</option> 
                        <option value="1">正常</option>
                        <option value="2">草稿</option>
                    }
                    else if (Model.State == 1)
                    {
                        <option value="0">全部</option> 
                        <option value="1" selected="selected">正常</option>
                        <option value="2">草稿</option>    
                    }
                    else
                    {
                        <option value="0">全部</option> 
                        <option value="1">正常</option>
                        <option value="2" selected="selected">草稿</option>
                    }
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">访问量</label>
            <div class="layui-input-block">
                <input type="text" name="Hits" lay-filter="hits" class="layui-input"  autocomplete="off" value="@Model.Hits" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">正文</label>
            <div class="layui-input-block">
                <textarea name="Content" lay-filter="content" id="content">@Model.Content</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit>保存</button>
                <button class="layui-btn layui-btn-primary" type="reset">重置</button>
            </div>
        </div>
    </form>
}
@section scripts
{

    <script>
        // document.getElementById("content").value="@Model.Content";
        layui.use(['form', 'layer', 'layedit'], function () {
            var form = layui.form, layer = layui.layer, $ = layui.jquery, layedit = layui.layedit;
            // $("#content").innerHTML();
            var content = layedit.build("content", { width: 600, uploadImage: { url: '@Url.Action("UploadImage", "Article")' } });

            form.verify({
                categoryName: function (value) {
                    if (value == '' || value == null) {
                        return '名称不对'
                    }
                }
            })
            var $item = $(".layui-nav > .layui-nav-item");
            $item.removeClass('layui-this').eq(2).addClass('layui-this');
        })
    </script>
}
